/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package parismetro;

import javafx.scene.CustomNode;
import javafx.scene.Group;
import javafx.scene.Node;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.scene.text.TextAlignment;
import modele.OrderList;
import java.text.DecimalFormat;

/**
 * @author Hadrien
 */
public class Cart extends CustomNode {

    public var groupAchat: Group = Group { content: [] };
    public var tout: Group = Group{ content : bind [s, groupAchat]};
    public-init var orderList: OrderList;

    public function doGroupAchat() {
        var g: Group = Group { content: [] };
        var i = 0;
        for (o in orderList.orders) {
            insert CadreCart { order: o; layoutX: 5; layoutY: 35+(i++)*85;isEnCours: (i==orderList.orders.size()) } into g.content;
        }
        groupAchat = g;
    }

    public var s: Group = Group {
                content: [
                    Rectangle {
                        width: 220
                        height: 380
                        arcWidth: 20, arcHeight: 20
                        fill: Color.rgb(0, 169, 157)
                    },
                    Text {
                        layoutX: 30, layoutY: 25
                        font: Font { size: 24, embolden: true, name: "Myriad Pro" }
                        content: "Achats en cours"
                        textAlignment: TextAlignment.CENTER
                        fill: Color.WHITE
                    },
                    Rectangle {
                        layoutX: 5, layoutY: 35
                        width: 210
                        height: 340
                        arcWidth: 15, arcHeight: 15
                        fill: Color.rgb(255, 255, 255)
                    },
                    Rectangle {
                        layoutY: 385
                        width: 220
                        height: 40
                        arcWidth: 20, arcHeight: 20
                        fill: Color.WHITE
                        stroke: Color.rgb(0, 169, 157)
                        strokeWidth: 5
                    },
                    Text {
                        layoutX: 10, layoutY: 418
                        font: Font { size: 34, embolden: true, name: "Myriad Pro" }
                        content: bind "Total {new DecimalFormat("0.00").format(orderList.total)}€"
                        textAlignment: TextAlignment.CENTER
                    }
                ]
            }

    override public function create(): Node {
        orderList.addObservateur(this);
        return tout;
    }

}
